<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <form>
        <div>
            <label for="">姓名</label>
            <input type="text" name="username" placeholder="姓名">
        </div>
        <div>
            <label for="">性别</label>
            <input type="radio" name="gender" value="男">男
            <input type="radio" name="gender" value="女">女
        </div>
        <button type="button">提交</button>
    </form>
    <script src="./js/jquery-1.12.4.js"></script>
    <script>
        //转数据格式
        $('button').on('click', function () {
            const paramsStr = $("form").serialize();
            console.log(paramsStr);
        })
        //转文件格式
        $('button').on('click', function () {
            let form = document.querySelector('form')
            let fd = new FormData(form)
            fd.forEach((val, key) => console.log(key, val))
        })
        // let but = document.querySelector('button')
        // but.onclick = function () {
        //     let form = document.querySelector('form')
        //     let fd = new FormData(form)
        //     fd.forEach((val, key) => console.log(key, val))
        // }
    </script>
</body>

</html>